package com.freewater.parking.domain.parking;

import com.freewater.parking.domain.common.Command;
import com.freewater.parking.domain.common.PlateNumber;
import org.apache.commons.lang3.Validate;

import java.time.LocalDateTime;
import java.util.Objects;

/**
 * 车辆出场命令
 */
public class CheckOutCommand implements Command {
    /**
     * 车牌号
     */
    private final PlateNumber plateNumber;
    /**
     * 出场时间
     */
    private final LocalDateTime checkOutTime;

    public CheckOutCommand(PlateNumber plateNumber) {
        this(plateNumber, LocalDateTime.now());
    }

    public CheckOutCommand(PlateNumber plateNumber, LocalDateTime checkOutTime) {
        Validate.notNull(plateNumber, "车牌号不能为空");
        Validate.notNull(checkOutTime, "车辆出场时间不能为空");
        this.plateNumber = plateNumber;
        this.checkOutTime = checkOutTime;
    }

    /**
     * 获取车牌号
     *
     * @return 车牌号
     */
    public PlateNumber getPlateNumber() {
        return plateNumber;
    }

    /**
     * 获取出场时间
     *
     * @return 出场时间
     */
    public LocalDateTime getCheckOutTime() {
        return checkOutTime;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        CheckOutCommand that = (CheckOutCommand) o;
        return Objects.equals(plateNumber, that.plateNumber) &&
                Objects.equals(checkOutTime, that.checkOutTime);
    }

    @Override
    public int hashCode() {
        return Objects.hash(plateNumber, checkOutTime);
    }
}
